Skip to content

fix: chain exceptions in get_prompt and read_resource handlers#2542

Merged
maxisbey merged 1 commit intomodelcontextprotocol:mainfrom
blackwell-systems:fix/chain-exceptions-server
May 8, 2026
Merged

fix: chain exceptions in get_prompt and read_resource handlers#2542
maxisbey merged 1 commit intomodelcontextprotocol:mainfrom
blackwell-systems:fix/chain-exceptions-server

Conversation

@blackwell-systems
Copy link
Copy Markdown
Contributor

Summary

Two raise statements in server/mcpserver/server.py discard the causal exception chain:

  • Line 1112: raise ValueError(str(e))raise ValueError(str(e)) from e
  • Line 451: raise ResourceError(...)raise ResourceError(...) from exc

Motivation and Context

The same file uses from exc correctly at line 459. These two sites are inconsistent and lose the original traceback, making it impossible for callers to programmatically inspect the root cause via __cause__.

Without from, Python shows "During handling of the above exception, another exception occurred" which is confusing. With from, it shows "The above exception was the direct cause of the following exception" and preserves the chain for isinstance() checks on __cause__.

How Has This Been Tested?

The change is purely additive (adds from clause) and does not alter control flow or exception types. Existing tests pass unchanged.

Fixes #2541

Two raise statements discarded the causal exception chain:

- Line 1112: raise ValueError(str(e)) → raise ValueError(str(e)) from e
- Line 451: raise ResourceError(...) → raise ResourceError(...) from exc

The same file already uses `from exc` correctly at line 459.
Without `from`, callers lose the original traceback and cannot
programmatically inspect the root cause via __cause__.

Fixes modelcontextprotocol#2541
Copy link
Copy Markdown
Contributor

@maxisbey maxisbey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix!

@maxisbey maxisbey merged commit bf3e001 into modelcontextprotocol:main May 8, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

raise ValueError(str(e)) discards exception chain in get_prompt handler

2 participants